/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.dbentities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author bms
 */
@Entity
@Table(name = "user", catalog = "tasks_management", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findByUserId", query = "SELECT u FROM User u WHERE u.userId = :userId"),
    @NamedQuery(name = "User.findByUserName", query = "SELECT u FROM User u WHERE u.userName = :userName"),
    @NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password"),
    @NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email = :email")})
public class User implements Serializable {
    @JoinColumn(name = "private_group", referencedColumnName = "group_id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private GroupEx privateGroup;

    private static final long serialVersionUID = 1L;
    
    @TableGenerator(name="User_Gen", table="ID_GEN", pkColumnName="GEN_NAME", valueColumnName="GEN_VAL")
    @Id @GeneratedValue(generator="User_Gen")
    @Basic(optional = false)
    @Column(name = "user_id", nullable = false)
    private Integer userId;
    @Basic(optional = false)
    @Column(name = "user_name", nullable = false, length = 100)
    private String userName;
    @Basic(optional = false)
    @Column(name = "password", nullable = false, length = 100)
    private String password;
    @Basic(optional = false)
    @Column(name = "email", nullable = false, length = 100)
    private String email;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.LAZY)
    private List<GroupMember> groupMemberList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.LAZY)
    private List<TaskUser> taskUserList;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.LAZY)
    private Session session;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "destUser", fetch = FetchType.LAZY)
    private List<TaskAssign> taskAssignedList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sourceUser", fetch = FetchType.LAZY)
    private List<TaskAssign> taskAssignList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "destUser", fetch = FetchType.LAZY)
    private List<GroupInvitation> groupInvitationRecievedList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sourceUser", fetch = FetchType.LAZY)
    private List<GroupInvitation> groupInvitationSendList;

    public User() {
    }

    public User(Integer userId) {
        this.userId = userId;
    }

    public User(Integer userId, String userName, String password, String email) {
        this.userId = userId;
        this.userName = userName;
        this.password = password;
        this.email = email;
    }
    
   public User(Integer userId, String userName, String password, String email, GroupEx prvGroup) {
        this.userId = userId;
        this.userName = userName;
        this.password = password;
        this.email = email;
        this.privateGroup = prvGroup;
    }    
   
   public User(String userName, String password, String email, GroupEx prvGroup) {
        this.userName = userName;
        this.password = password;
        this.email = email;
        this.privateGroup = prvGroup;
    }   
    
    public User(String userName, String password, String email) {
        this.userName = userName;
        this.password = password;
        this.email = email;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    
       public String getEmail() {
        return email;
    }

    
    public String getPassword() {
        return password;
    }

    
    public Integer getUserId() {
        return userId;
    }

    
    public String getUserName() {
        return userName;
    }
    
    @XmlTransient
    public List<GroupMember> getGroupMemberList() {
        return groupMemberList;
    }

    public void setGroupMemberList(List<GroupMember> groupMemberList) {
        this.groupMemberList = groupMemberList;
    }

    @XmlTransient
    public List<TaskUser> getTaskUserList() {
        return taskUserList;
    }

    public void setTaskUserList(List<TaskUser> taskUserList) {
        this.taskUserList = taskUserList;
    }

    public Session getSession() {
        return session;
    }

    public void setSession(Session session) {
        this.session = session;
    }

    @XmlTransient
    public List<TaskAssign> getTaskAssignedList() {
        return taskAssignedList;
    }

    public void setTaskAssignedList(List<TaskAssign> taskAssignList) {
        this.taskAssignedList = taskAssignList;
    }

    @XmlTransient
    public List<TaskAssign> getTaskAssignList1() {
        return taskAssignList;
    }

    public void setTaskAssignList1(List<TaskAssign> taskAssignList1) {
        this.taskAssignList = taskAssignList1;
    }

    @XmlTransient
    public List<GroupInvitation> getGroupInvitations() {
        return groupInvitationRecievedList;
    }

    public void setGroupInvitations(List<GroupInvitation> groupInvitationList) {
        this.groupInvitationRecievedList = groupInvitationList;
    }

    @XmlTransient
    public List<GroupInvitation> getGroupInvitationList1() {
        return groupInvitationSendList;
    }

    public void setGroupInvitationList1(List<GroupInvitation> groupInvitationList1) {
        this.groupInvitationSendList = groupInvitationList1;
    }

    
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    
    public String toString() {
        return "cs575.dbentities.User[ userId=" + userId + " ]";
    }

    public GroupEx getPrivateGroup() {
        return privateGroup;
    }

    public void setPrivateGroup(GroupEx privateGroup) {
        this.privateGroup = privateGroup;
    }
    
}
